#ifndef MYSERVER_H
#define MYSERVER_H

#include <list>

#include "MyConnectedClient.h"
#include "MyTools.h"
#include "MyThread.h"
#include "MyMsgIn.h"

class MyServer: public MyThread
{
public:
    MyServer();
    ~MyServer();

    void ListenTo(const unsigned int &port);
    void StopListen();
    bool IsListening();

protected:

    // server thread will access member below
    // ensure shared data safety using Lock()/Unlock();
    std::list<MyConnectedClient*> mConnectedClients;
    virtual void OnReadyToListen(bool ready) = 0;
    virtual void OnClientConnect(MyConnectedClient *client) = 0;
    virtual void OnClientDisconnect(MyConnectedClient *client) = 0;
    virtual void OnReceiveMessage(MyConnectedClient *client, MyMsgIn &msg) = 0;

private:
    bool mListening;
    ENetHost *mHost;
    ENetAddress mAddress;
    unsigned int mPort;
    void Run();
};

#endif
